from myelin.Ns import MYELINS
from nodetypes.ntypes.SparqlService.query.libmml.forms.Reset import Form

from nodetypes import config

#DefaultNsMapString = u''.join([
#    u'%s = %s\n' % (k,v)
#    for k,v in config.DEFAULT_VERSA_NSMAP.iteritems()
#])
#try:
#    del k,v
#except:
#    pass

class Form(Form):
    
    #defaultNsMapString = DefaultNsMapString
    defaultPrettyMethods = config.DEFAULT_PRETTY_METHODS
    defaultSubmitAction = u'query'
    
    def createInstance(self, context, node):
        #defaults = context.defaults
        #map = context.uriMapper.apply
        
        eventData = context.event.data
        model = context.model
        
        nxa = node.xml_append
        nxc = node.xml_create_element
        
        self.createMethodOptions(
            context,
            nxa(
                nxc(
                    u'a:method', MYELINS
                )            
            ),
            (context.nodeType.actions.get(self.defaultSubmitAction) or {}).keys()
        )
        
        self.createDefaultGraphsOptions(
            context,
            nxa(
                nxc(
                    u'a:default-graphs', MYELINS
                )
            )
        )
        
        if context.method in self.defaultPrettyMethods:
            nxa(
                nxc(
                    u'a:nsmaps', MYELINS,
                    content = eventData.config.defaultNsMapString
                )
            )
        else:
            nxa(
                nxc(
                    u'a:nsmaps', MYELINS
                )
            )   
        
        nxa(
            nxc(
                u'a:query', MYELINS
            )
        )        
        
        return node
    

del config